lobsterlayui.main(['index', 'layer', 'form', 'element', 'table', 'laydate'], {
    data: {
        table: null,
        tableoptions: {},
        layerindex: 0,
        selectdata: {},
    },
    pageload: function (right) {
        console.log(right);
        var sdate = this.getStartTime();
        var edate = this.getEndTime();
        if (sdate && edate) {
            $("#date").val(sdate + ' ~ ' + edate)
        }
        this.initevent();
        this.loaddata();
    },
    //初始化事件
    initevent: function () {
        var self = this;
        //查找reload,通过条件，查询网格的table重载数据显示到界面
        layui.form.on("submit(LAY-app-front-search)", function (data) {
            self.loaddata();
        });
        layui.laydate.render({
            elem: '#date'
            , type: 'date'
            , range: '~'
            , format: 'yyyy-MM-dd'
        });
    },
    //加载订单列表
    loaddata: function () {
        var self = this;
        var date = $("#date").val() || "";
        self.data.table = layui.table.render({
            elem: '#datatable',
            where: {
                orderNo: $("[name='orderNo']").val(),
                refundStatus: $("[name='refundStatus']").val(),
                sdate: date.split(' ~ ')[0],
                edate: date.split(' ~ ')[1],
            },
            headers:lobsterlayui.GetHeaderData(),
            url: lobsterlayui.GetLowCodeUrl("tspay.getrefundlist"),
            height: 'full-130',
            cellMinWidth: 80,
            size: 'sm',
            page: true,
            cols: [[
                { width: "200", field: 'OrderNo', title: '订单号', fixed: 'left' },
                { width: "200", field: 'BusinessOrderNo', title: '业务订单号', fixed: 'left' },
                { width: "200", field: 'RefundNo', title: '退款单号', fixed: 'left' },
                { width: "200", field: 'BusinessRefundNo', title: '业务退款单号', fixed: 'left' },
                { width: "100", field: 'RefundFee', title: '退款金额' },
                {
                    width: "200", field: 'RefundDate', title: '退款时间', templet: function (d) {
                        return (d.RefundDate || "").substring(0, 19);
                    }
                },
                {
                    width: "100", field: 'RefundStatus', title: '退款时间', templet: function (d) {
                        if (d.RefundStatus == 0)
                            return '退款中';
                        else if (d.RefundStatus == 1)
                            return '退款成功'
                    }
                },
                { width: "200", field: 'SuccessTime', title: '退款成功时间' },
                { width: "200", field: 'RefundDesc', title: '退款说明' },
                { width: "200", field: 'TransactionId', title: '退款第三方流水号' },
            ]],
            parseData: function (res) {
                return {
                    code: res.code,
                    msg: res.msg,
                    count: res.data.count,
                    data: res.data.data
                }
            },
        })
    },
    getEndTime: function () {
        var mdate = new Date();
        var year = mdate.getFullYear();
        var month = mdate.getMonth() + 1;
        if (month < 10)
            month = "0" + month;
        var ddate = mdate.getDate();
        if (ddate < 10)
            ddate = "0" + ddate;
        return year + "-" + month + "-" + ddate;
    },
    getStartTime: function () {
        var mdate = new Date();
        var year = mdate.getFullYear();
        var month = mdate.getMonth() + 1;
        if (month < 10)
            month = "0" + month;
        var ddate = mdate.getDate() - 3;
        if (ddate < 10)
            ddate = "0" + ddate;
        return year + "-" + month + "-" + ddate;
    }
})